﻿<UserControl x:Class="TorchView.SharedStashEditor.Views.InventoryEditor"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
             xmlns:local="clr-namespace:TorchView.SharedStashEditor"
             xmlns:vm="clr-namespace:TorchView.SharedStashEditor.ViewModels"
             xmlns:helper="clr-namespace:TorchView.SharedStashEditor.Helpers"
             mc:Ignorable="d" 
             d:DesignHeight="300" d:DesignWidth="300">

    <UserControl.Resources>
        <helper:GetPropertiesConverter x:Key="GetPropertiesConverter" />

        <HierarchicalDataTemplate DataType="{x:Type local:PropertyViewModel}" ItemsSource="{Binding SubItems}">
            <StackPanel Orientation="Horizontal">
                <TextBlock Text="{Binding Property}"/>
                <TextBlock Text=": "/>
                <TextBlock Text="{Binding Value}"/>
            </StackPanel>
        </HierarchicalDataTemplate>
    </UserControl.Resources>

    <Grid>
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="Auto" />
            <ColumnDefinition Width="*" />
        </Grid.ColumnDefinitions>
        <Grid Grid.Column="0">
            <Grid.RowDefinitions>
                <RowDefinition Height="*"/>
                <RowDefinition Height="Auto"/>
            </Grid.RowDefinitions>
            <ListBox Grid.Row="0" Name="ItemListBox" ItemsSource="{Binding ItemSlot}" SelectedItem="{Binding SelectedSlot}" IsSynchronizedWithCurrentItem="True">
                <ListBox.ItemTemplate>
                    <DataTemplate>
                        <TextBlock Text="{Binding Name}"/>
                    </DataTemplate>
                </ListBox.ItemTemplate>
            </ListBox>
                     
            <StackPanel Grid.Row="1" Orientation="Horizontal">
                <Button Command="{Binding AddItemCommand}" Content="Add Item"></Button>
                <Button Command="{Binding RemoveItemCommand}" Content="Remove Item"></Button>
            </StackPanel>
        </Grid>
        <TabControl Grid.Column="1">
            <TabItem Header="Edit" DataContext="{Binding ElementName=ItemListBox, Path=SelectedItem.Item, Mode=OneWay}">
                <Grid>
                    <Grid.RowDefinitions>
                        <RowDefinition Height="Auto" />
                        <RowDefinition Height="Auto" />
                        <RowDefinition Height="Auto" />
                        <RowDefinition Height="Auto" />
                        <RowDefinition Height="Auto" />
                        <RowDefinition Height="Auto" />
                        <RowDefinition Height="Auto" />
                        <RowDefinition Height="Auto" />
                        <RowDefinition Height="Auto" />
                        <RowDefinition Height="Auto" />
                        <RowDefinition Height="Auto" />
                        <RowDefinition Height="Auto" />
                    </Grid.RowDefinitions>
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="Auto"/>
                        <ColumnDefinition Width="Auto"/>
                    </Grid.ColumnDefinitions>
                    <Label Grid.Row="0" Grid.Column="0" Target="{Binding ElementName=ItemName}">Name:</Label>
                    <TextBox Grid.Row="0" Grid.Column="1" Name="ItemName" Text="{Binding Name}"></TextBox>

                    <Label Grid.Row="1" Grid.Column="0" Target="{Binding ElementName=ItemPrefix}">Prefix:</Label>
                    <TextBox Grid.Row="1" Grid.Column="1" Name="ItemPrefix" Text="{Binding Prefix}"></TextBox>

                    <Label Grid.Row="2" Grid.Column="0" Target="{Binding ElementName=ItemSuffix}">Suffix:</Label>
                    <TextBox Grid.Row="2" Grid.Column="1" Name="ItemSuffix" Text="{Binding Suffix}"></TextBox>

                    <Label Grid.Row="3" Grid.Column="0" Target="{Binding ElementName=ItemTimesHeirloomed}">Times Heirloomed:</Label>
                    <TextBox Grid.Row="3" Grid.Column="1" Name="ItemTimesHeirloomed" Text="{Binding TimesHeirloomed}"></TextBox>

                    <Label Grid.Row="4" Grid.Column="0" Target="{Binding ElementName=ItemTimesEnchanted}">Times Enchanted:</Label>
                    <TextBox Grid.Row="4" Grid.Column="1" Name="ItemTimesEnchanted" Text="{Binding TimesEnchanted}"></TextBox>

                    <Label Grid.Row="5" Grid.Column="0" Target="{Binding ElementName=ItemStack}">Stack:</Label>
                    <TextBox Grid.Row="5" Grid.Column="1" Name="ItemStack" Text="{Binding Stack}"></TextBox>

                    <Label Grid.Row="6" Grid.Column="0" Target="{Binding ElementName=ItemTotalSockets}">Total Sockets:</Label>
                    <TextBox Grid.Row="6" Grid.Column="1" Name="ItemTotalSockets" Text="{Binding TotalSockets}"></TextBox>

                    <Label Grid.Row="7" Grid.Column="0" Target="{Binding ElementName=ItemMaxDamage}">Max Damage:</Label>
                    <TextBox Grid.Row="7" Grid.Column="1" Name="ItemMaxDamage" Text="{Binding MaxDamage}"></TextBox>

                    <Label Grid.Row="8" Grid.Column="0" Target="{Binding ElementName=ItemArmor}">Armor:</Label>
                    <TextBox Grid.Row="8" Grid.Column="1" Name="ItemArmor" Text="{Binding Armor}"></TextBox>

                    <StackPanel Grid.Row="9" Grid.ColumnSpan="2" Orientation="Vertical">
                        <Label Target="{Binding ElementName=ItemDamages}">Bonus Damages</Label>
                        <ListBox Name="ItemDamages" ItemsSource="{Binding BonusDamage}"  SelectedItem="{Binding SelectedDamage, Mode=OneWayToSource}"></ListBox>
                        <StackPanel Orientation="Horizontal">
                            <Button Command="{Binding AddDamageBonusCommand}">Add Damage</Button>
                            <Button Command="{Binding EditDamageBonusCommand}">Edit Damage</Button>
                            <Button Command="{Binding RemoveDamageBonusCommand}">Remove Damage</Button>
                        </StackPanel>
                    </StackPanel>

                    <TabControl Grid.Row="10" Grid.ColumnSpan="2" ItemsSource="{Binding EffectLists}" SelectedIndex="{Binding SelectedEffectList, Mode=OneWay}">
                        <TabControl.ItemTemplate>
                            <DataTemplate>
                                <TextBlock Text="{Binding Name}"/>
                            </DataTemplate>
                        </TabControl.ItemTemplate>
                        <TabControl.ContentTemplate>
                            <DataTemplate DataType="{x:Type vm:EffectListViewModel}">
                                <StackPanel Grid.Row="10" Grid.ColumnSpan="2" Orientation="Vertical">
                                    <ListBox Name="Effects" ItemsSource="{Binding EffectList}" SelectedItem="{Binding SelectedEffect, Mode=OneWayToSource}"></ListBox>
                                    <StackPanel Orientation="Horizontal">
                                        <Button Command="{Binding AddEffectCommand}">Add Effect</Button>
                                        <Button Command="{Binding EditEffectCommand}">Edit Effect</Button>
                                        <Button Command="{Binding RemoveEffectCommand}">Remove Effect</Button>
                                    </StackPanel>
                                </StackPanel>
                            </DataTemplate>
                        </TabControl.ContentTemplate>
                    </TabControl>

                    <Button Grid.Row="11" Grid.Column="0" Command="{Binding AddAffixCommand}">Add Affix</Button>
                </Grid>
            </TabItem>
            <TabItem Header="Properties">
                <TreeView ItemsSource="{Binding ElementName=ItemListBox, Path=SelectedItem.Item.InnerItem, Converter={StaticResource GetPropertiesConverter}}" Name="ItemView" VerticalAlignment="Top"/>
            </TabItem>
        </TabControl>
    </Grid>
</UserControl>
